package com.ruoyi.gams.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.gams.service.IGamsBusinessQueueService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gams.domain.GamsDevice;
import com.ruoyi.gams.service.IGamsDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备Controller
 *
 * @author ruoyi
 * @date 2021-09-03
 */
@RestController
@RequestMapping("/gams/device")
public class GamsDeviceController extends BaseController
{
    @Autowired
    private IGamsDeviceService gamsDeviceService;

    @Autowired
    private IGamsBusinessQueueService businessQueueService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('gams:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(GamsDevice gamsDevice)
    {
        startPage();
        List<GamsDevice> list = gamsDeviceService.selectGamsDeviceList(gamsDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('gams:device:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GamsDevice gamsDevice)
    {
        List<GamsDevice> list = gamsDeviceService.selectGamsDeviceList(gamsDevice);
        ExcelUtil<GamsDevice> util = new ExcelUtil<GamsDevice>(GamsDevice.class);
        return util.exportExcel(list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('gams:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(gamsDeviceService.selectGamsDeviceById(id));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('gams:device:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GamsDevice gamsDevice)
    {
        return toAjax(gamsDeviceService.insertGamsDevice(gamsDevice));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('gams:device:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GamsDevice gamsDevice)
    {
        return toAjax(gamsDeviceService.updateGamsDevice(gamsDevice));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('gams:device:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(gamsDeviceService.deleteGamsDeviceByIds(ids));
    }

    /**
     * 全部业务列表
     */
    @ResponseBody
    @PostMapping("/businessList")
    public TableDataInfo businessList()
    {
        List<Map<String, Object>> list = businessQueueService.findQueueListWithCount(null);
        return getDataTable(list);
    }
}
